﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.ChallengeCopy.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;
    import mortal.game.view.medal.*;

    public class ChallengeLevelRender extends GSprite
    {
        private var _challengeData:ChallengeData;
        private var _iconSprite:ToolTipSprite;
        private var _currentIndex:int;
        private var _nameBg:GImageBitmap;
        private var _icon:GImageBitmap;
        private var _name:GImageBitmap;
        private var _medalBg:GImageBitmap;
        private var _medalLvIcon:GImageBitmap;
        private var _medalLevel:BitmapNumberText;
        private var _treasureIcon:GImageBitmap;
        private var _levelNum:BitmapNumberText;
        private var _posTxt:GTextFiled;
        private var _rewardList:Vector.<BaseItem>;

        public function ChallengeLevelRender()
        {
            this._rewardList = new Vector.<BaseItem>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._iconSprite = UICompomentPool.getUICompoment(ToolTipSprite);
            this.addChild(this._iconSprite);
            this._icon = UIFactory.gImageBitmap("", 0, 0, this._iconSprite);
            this._nameBg = UIFactory.gImageBitmap("", 25, 115, this._iconSprite);
            this._name = UIFactory.gImageBitmap("", 0, 127, this._iconSprite, this.updateIconSize);
            this._treasureIcon = UIFactory.gImageBitmap("", 0, 127, null, this.updateIconSize);
            this._treasureIcon.imgUrl = ImagesConst.ChallengeTreasureBig;
            this._medalBg = UIFactory.gImageBitmap(ImagesConst.ChallengeRenderMedalBg, 0, 0, null);
            this._medalLvIcon = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_12, 0, 0, null);
            this._medalLevel = UIFactory.bitmapNumberText(0, 0, "FightInfoNum.png", 12, 15, -1, null);
            this._levelNum = UIFactory.bitmapNumberText(44, 124, "PetGrowYellowNum.png", 18, 21, -2, this._iconSprite, 9);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._icon.dispose(param1);
            this._icon = null;
            this._nameBg.dispose(param1);
            this._nameBg = null;
            this._levelNum.dispose(param1);
            this._levelNum = null;
            this._name.dispose(param1);
            this._name = null;
            this._treasureIcon.dispose(param1);
            this._treasureIcon = null;
            this._iconSprite.dispose(param1);
            this._iconSprite = null;
            this._medalBg.dispose(param1);
            this._medalBg = null;
            this._medalLvIcon.dispose(param1);
            this._medalLvIcon = null;
            this._medalLevel.dispose(param1);
            this._medalLevel = null;
            if (this._posTxt)
            {
                this._posTxt.dispose(param1);
                this._posTxt = null;
            }
            this.removeRewardItems();
            this._challengeData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateIconSize() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._currentIndex == this._challengeData.currentSectionMaxLevel)
            {
                if (this._currentIndex == this._challengeData.passLevel)
                {
                    this._name.x = (131 - this._name.width) * 0.5 + this._nameBg.x + 15;
                }
                else
                {
                    this._name.x = this._treasureIcon.x + 75;
                }
                this._name.y = 130;
            }
            else
            {
                this._name.x = (131 - 38 - this._name.width) * 0.5 + this._nameBg.x + 27;
                this._name.y = 127;
            }
            this._name.visible = true;
            this._iconSprite.addChild(this._treasureIcon);
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this._challengeData = param1.data;
            this._currentIndex = param1.index;
            if (this._currentIndex == this._challengeData.currentSectionMaxLevel)
            {
                this._nameBg.imgUrl = ImagesConst.ChallengeBossNameBg;
                this._treasureIcon.visible = true;
                this._nameBg.x = -25;
                this._levelNum.x = -20;
                this._treasureIcon.x = -55;
                this._treasureIcon.y = 92;
                this._levelNum.text = "";
            }
            else
            {
                this._nameBg.imgUrl = ImagesConst.ChallengeLevelNameBg;
                this._treasureIcon.visible = false;
                this._nameBg.x = 20;
                this._levelNum.x = 32;
                this._treasureIcon.x = 120;
                this._treasureIcon.y = 107;
                this._levelNum.text = this._currentIndex.toString();
            }
            var _loc_2:* = ChallengeUtil.isCanEnterStateByTChallenge(this._challengeData.tChallengCopy, this._currentIndex);
            if (_loc_2 == -1)
            {
                EffectManager.glowFilterUnReg(this);
                this.filters = [FilterConst.colorFilter2];
                this.updateRewardList();
            }
            else if (_loc_2 == 0)
            {
                EffectManager.glowFilterReg(this);
                this.filters = [];
                this.updateRewardList();
            }
            else if (_loc_2 == 1)
            {
                EffectManager.glowFilterUnReg(this);
                this.filters = [];
            }
            this._name.imgUrl = "ExpeditionName_" + ChallengeUtil.getLevelUrlByTChallenge(this._challengeData.tChallengCopy, this._currentIndex);
            this._icon.imgUrl = "ExpeditionIcon_" + ChallengeUtil.getLevelUrlByTChallenge(this._challengeData.tChallengCopy, this._currentIndex);
            this._iconSprite.toolTipData = ChallengeCopyConfig.instance.challengCopyDic[this._challengeData.tChallengCopy.tower][this._challengeData.tChallengCopy.section][this._currentIndex];
            return;
        }// end function

        private function updateRewardList() : void
        {
            var _loc_2:BaseItem = null;
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_7:int = 0;
            this.removeRewardItems();
            var _loc_1:* = GameController.copy.challengeCopy.view as ChallengeCopyModule;
            var _loc_3:* = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(this._challengeData.tChallengCopy.tower, this._challengeData.tChallengCopy.section, this._currentIndex);
            var _loc_4:* = _loc_3.reward.split("&");
            while (_loc_7 < _loc_4.length)
            {
                
                if (_loc_4[_loc_7])
                {
                    _loc_5 = (_loc_4[_loc_7] as String).split("#");
                    _loc_6 = new ItemData(int(_loc_5[0]));
                    if (_loc_6.itemInfo && ItemsUtil.isFitCarrer(_loc_6))
                    {
                        _loc_2 = UICompomentPool.getUICompoment(BaseItem);
                        _loc_2.setItemStyle(24, null, 2, 2);
                        var _loc_9:Boolean = false;
                        _loc_2.isDropAble = false;
                        _loc_2.isDragAble = _loc_9;
                        _loc_2.isShowLock = false;
                        _loc_2.itemData = _loc_6;
                        _loc_2.amount = _loc_5[1];
                        _loc_1.mapPanel.addChild(_loc_2);
                        this._rewardList.push(_loc_2);
                        _loc_2.filters = this.filters;
                    }
                }
                _loc_7++;
            }
            var _loc_8:* = MedalConfig.instance.getTmedalByCode(_loc_3.medalId);
            if (_loc_8)
            {
                _loc_2 = UICompomentPool.getUICompoment(BaseItem);
                _loc_2.setItemStyle(30, null, 2, 2);
                var _loc_9:Boolean = false;
                _loc_2.isDropAble = false;
                _loc_2.isDragAble = _loc_9;
                _loc_2.isShowLock = false;
                _loc_2.source = MedalUtil.getMedalIconUrlByTmedal(_loc_8, 1);
                _loc_2.toolTipData = _loc_8;
                this._medalLevel.text = "" + _loc_8.typeLevel;
                this._rewardList.push(_loc_2);
                _loc_1.mapPanel.addChild(this._medalBg);
                _loc_1.mapPanel.addChild(this._medalLvIcon);
                _loc_1.mapPanel.addChild(this._medalLevel);
                _loc_1.mapPanel.addChild(_loc_2);
            }
            _loc_7 = 0;
            while (_loc_7 < this._rewardList.length)
            {
                
                if (this._currentIndex == this._challengeData.currentSectionMaxLevel)
                {
                    this._rewardList[_loc_7].y = 163 + this.y;
                    this._rewardList[_loc_7].x = _loc_7 * 35 + (190 - 45 * this._rewardList.length) * 0.5 - 5 + this.x;
                }
                else
                {
                    this._rewardList[_loc_7].y = 154 + this.y;
                    this._rewardList[_loc_7].x = _loc_7 * 35 + (225 - 45 * this._rewardList.length) * 0.5 - 5 + this.x;
                }
                _loc_7++;
            }
            if (_loc_8)
            {
                _loc_2.x = _loc_2.x - 2;
                _loc_2.y = _loc_2.y - 4;
                this._medalBg.x = _loc_2.x + _loc_2.width - 30;
                this._medalBg.y = _loc_2.y + _loc_2.height - 30;
                this._medalLvIcon.x = _loc_2.x + _loc_2.width - 9;
                this._medalLvIcon.y = _loc_2.y + _loc_2.height - 22;
                this._medalLevel.x = _loc_2.x + _loc_2.width + 11;
                this._medalLevel.y = _loc_2.y + _loc_2.height - 20;
            }
            return;
        }// end function

        private function removeRewardItems() : void
        {
            var _loc_1:BaseItem = null;
            for each (_loc_1 in this._rewardList)
            {
                
                _loc_1.dispose(true);
            }
            this._rewardList.length = 0;
            return;
        }// end function

        public function showCurrentPos() : void
        {
            if (this._posTxt == null)
            {
                this._posTxt = UIFactory.gTextField("", 60, 150, 100, 20, this, GlobalStyle.textFormatItemGreen);
                this._posTxt.selectable = true;
            }
            this._posTxt.text = this.x + "," + this.y;
            return;
        }// end function

    }
}
